package com.pvj.myaccount.ui.gallery

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pvj.myaccount.repository.HomeRepository
import com.pvj.myaccount.room.entity.Cost
import com.pvj.myaccount.uitls.TimeUtil
import kotlinx.coroutines.launch

class GalleryViewModel : ViewModel() {
    private val repository = HomeRepository()

    private val _costList = MutableLiveData<List<Cost>?>()
    val monthList: LiveData<List<Cost>?> = _costList

    fun loadMonthData(year: Int, month: Int) {
        val todayStart = TimeUtil.getFirstDayOfMonthTimestamp(year,month)
        val todayEnd = TimeUtil.getLastDayOfMonthTimestamp(year,month)
       Log.d("","loadMonthData year:${year} month:${month}  ;start:${todayStart} end:${todayEnd}")

        viewModelScope.launch {
            val data = repository.getData(todayStart, todayEnd)
            // 更新LiveData
            _costList.postValue(data)
        }
    }


}